﻿using DevExpress.XtraEditors;
using DLL;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class AddEduClass : Form
    {
        public string ClassGuid = "";
        public string sql ="" ;
        public string DiseasesGuid = "";
        public AddEduClass(string classguid, string diseasesguid)
        {
            InitializeComponent();
            if (classguid == "-1")
            {
                Text = "新增分类";
                DiseasesGuid = diseasesguid;
                sql = @"insert  into [BNNursingDocsSystem_Develop].[dbo].[HealthEduClass]  (Class,ClassGuid,DiseasesGuid,OrderNum) values ";
            }
            else
            {
                Text = "修改分类";
                ClassGuid = classguid;
                sql = @"SELECT * FROM [BNNursingDocsSystem_Develop].[dbo].[HealthEduClass](NOLOCK) where ClassGuid ='"+ClassGuid+"'";
                DataTable Class = SqlHelper.ExecuteDataset(sql, CommandType.Text).Tables[0];
                textEdit1.Text = Class.Rows[0]["Class"].ToString();
                textEdit2.Text = Class.Rows[0]["OrderNum"].ToString();
                sql = @"update  [BNNursingDocsSystem_Develop].[dbo].[HealthEduClass]  set ";
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.No;
            Close();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.OK;
            if (Text == "新增分类")
            {
                string guid = Guid.NewGuid().ToString();
                sql += @" ('" + textEdit1.Text + "','" + guid + "','" + DiseasesGuid + "','" + textEdit2.Text + "')";
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql);
                sql = @" insert into [BNNursingDocsSystem_Develop].[dbo].[HealthEduContent] (ProjectContent,ProjectGuid) values ('"+" "+"','" + guid + "')";
                XtraMessageBox.Show("新增成功!");
                Close();
            }
            else
            {
                sql += @"Class ='"+textEdit1.Text+"' , OrderNum ='"+textEdit2.Text+"' where ClassGuid = '"+ClassGuid+"'";
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql);
                XtraMessageBox.Show("修改成功!");
                Close();
            }
        }
    }
}
